/**
 * merge level=99
 */
Ext.Ajax.on('requestcomplete', function(conn, response, options) {
			if (response.getResponseHeader) {
				var sessionStatus = response.getResponseHeader("sessionstatus");
				if (typeof(sessionStatus) != "undefined") {
					Ext.MessageBox.show({
								title : '服务器超时',
								msg : '服务器登录超时，您需要重新登录系统。',
								buttons : Ext.MessageBox.OK,
								width : 250,
								icon : Ext.MessageBox.WARNING,
								fn : function() {
									var redirect = 'login.jsp';
									window.location = redirect
								}
							})
				}
			}
		});

Ext.Ajax.on('requestexception', function(conn, response, options) {

		});

var alertFallback = false;
if (typeof console === "undefined" || typeof console.log === "undefined") {
	console = {};
	if (alertFallback) {
		console.log = function(msg) {
			alert(msg);
		};
	} else {
		console.log = function() {
		};
	}
}

Ext.namespace('Jfok');
Ext.Loader.setPath('Ext.ux', 'extjs4/ux');
Ext.QuickTips.init();
delete Ext.tip.Tip.prototype.minWidth;
Ext.application({
			name : 'Jfok',
			appFolder : 'js',

			controllers : ['TopRegion', 'BottomRegion', 'MainRegion', 'MenuRegion',
					'Module', 'ModuleForm', 'ModuleToolbar', 'ModuleAdditionFunction',
					'GridNavigate', 'GridNavigateTree', 'Attachment', 'Auditing',
					'Approve', 'HomePagePanel', 'Chart', 'report.Report',
					'report.DateSectionSelect', 'report.NavigateSelectFieldsTree',
					'Jfok.controller.report.ResultListGridToolbar'],

			launch : function() {
				var me = this;
				var systemInfo;
				Ext.themeName = Cookies.get('theme', 'neptune');
				Ext.Ajax.request({
							url : 'systemandlogininfo.do',
							async : false, // 不需要异步操作
							success : function(response) {
								systemInfo = Ext.decode(response.responseText);
								// console.log(systemInfo);
							}
						});
				Jfok.modules = Ext.create('Jfok.system.Modules', systemInfo);
				Jfok.system = Ext.create('Jfok.system.System', systemInfo);
				Jfok.system.setViewport(Ext.create('Jfok.view.region.Viewport'));
				Jfok.mainRegion = me.getApplication().getController('MainRegion');

				// 初始化好后立即加载的模块
				Ext.each(Jfok.system.getAutoOpenModules(), function(m) {
							Jfok.mainRegion.addModuleToMainRegion(m);
						});
				Jfok.system.viewport.down('mainregion').setActiveTab(0);

				setTimeout(function() {
							Ext.get("loading").remove();
						}, 100);
			}
		});

// 处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外
function forbidBackSpace(e) {
	var ev = e || window.event; // 获取event对象
	var obj = ev.target || ev.srcElement; // 获取事件源
	var t = obj.type || obj.getAttribute('type'); // 获取事件源类型
	// 获取作为判断条件的事件类型
	var vReadOnly = obj.readOnly;
	var vDisabled = obj.disabled;
	// 处理undefined值情况
	vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
	vDisabled = (vDisabled == undefined) ? true : vDisabled;
	// 当敲Backspace键时，事件源类型为密码或单行、多行文本的，
	// 并且readOnly属性为true或disabled属性为true的，则退格键失效
	var flag1 = ev.keyCode == 8
			&& (t == "password" || t == "text" || t == "textarea")
			&& (vReadOnly == true || vDisabled == true);
	// 当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效
	var flag2 = ev.keyCode == 8 && t != "password" && t != "text"
			&& t != "textarea";
	// 判断
	if (flag2 || flag1)
		return false;
}
// 禁止后退键 作用于Firefox、Opera
document.onkeypress = forbidBackSpace;
// 禁止后退键 作用于IE、Chrome
document.onkeydown = forbidBackSpace;
